package com.codi.fcloud.ufx.hssale.acco;

import com.codi.base.log.annotation.Loggable;
import com.codi.base.util.ExceptionUtil;
import com.codi.bus.exception.HundsunAPIException;
import com.codi.fcloud.ufx.UfxSDKFactory;
import com.codi.fcloud.ufx.constant.HSInputParameterNames;
import com.codi.fcloud.ufx.constant.UrlConstants;
import com.codi.trade.dto.BankinfoModAcctDto;
import com.codi.trade.service.BankinfoModAcctService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2018/3/1.
 */
@Slf4j
@Service("bankinfoModAcct")
public class BankinfoModAcct extends UfxSDKFactory implements BankinfoModAcctService {

    @Override
    protected String getTarget() {
        return UrlConstants.PREFIX_SALE + UrlConstants.BANKINFO_MOD_ACCT;
    }

    @Override
    @Loggable
    public Map<String, Object> modAcct(BankinfoModAcctDto dto) {
        String trustWay = apiValueMap.get(HSInputParameterNames.TRUST_WAY);
        Map<String, Object> request = new HashMap<>();

        request.put("trust_way", trustWay);
        request.put("net_no", getString(dto.getNet_no(), "0001"));
        request.put("trade_acco", getString(dto.getTrade_acco()));
        request.put("ta_acco", getString(dto.getTa_acco()));
        request.put("password", getString(dto.getPassword()));
        request.put("apply_time", getString(dto.getApply_time()));
        request.put("order_date", getString(dto.getOrder_date()));
        request.put("bank_info_type", getString(dto.getBank_info_typ(),"2"));
        request.put("bank_no", getString(dto.getBank_no()));
        request.put("bank_name", getString(dto.getBank_name()));
        request.put("bank_account_name", getString(dto.getBank_account_name()));
        request.put("bank_account", getString(dto.getBank_account()));
        request.put("capital_mode", getString(dto.getCapital_mode()));
        request.put("original_bank_no", getString(dto.getOriginal_bank_no()));
        request.put("original_bank_account", getString(dto.getOriginal_bank_account()));
        request.put("fund_card", getString(dto.getFund_card()));
        request.put("branchbank", getString(dto.getBranchbank()));
        request.put("bank_open_id_kind_gb", getString(dto.getBank_open_id_kind_gb()));
        request.put("bank_open_id_no", getString(dto.getBank_open_id_no()));
        request.put("detail_fund_way", getString(dto.getDetail_fund_way()));
        request.put("busin_ass_code", getString(dto.getBusin_ass_code()));
        request.put("original_fund_way", getString(dto.getOriginal_fund_way()));
        request.put("remittance_no", getString(dto.getRemittance_no(),"01"));
        request.put("bank_account_name_long", getString(dto.getBank_account_name_long()));
        request.put("fund_interface_type", getString(dto.getFund_interface_type()));
        request.put("channel_serial_id", getString(dto.getChannel_serial_id()));
        request.put("app_bank_account_flag", getString(dto.getApp_bank_account_flag()));
        request.put("redem_bank_account_flag", getString(dto.getRedem_bank_account_flag()));
        request.put("pre_check_flag", getString(dto.getPre_check_flag()));
        request.put("trade_source", getString(dto.getTrade_source()));
        request.put("net_modify_bankacco", getString(dto.getNet_modify_bankacco()));



        try {
            Map<String, Object> response = getUfxSDK().transact(getTarget(), request);

            return appendLog(request, response);
        } catch (Exception exception) {
            ExceptionUtil.logError(logger, getTarget(), exception);
            throw new HundsunAPIException(ExceptionUtil.getMessage(exception));
        }
    }
}
